package com.joyson.app.module.loginRegister;

import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.ScreenUtils;
import com.example.zhouwei.library.CustomPopWindow;
import com.jakewharton.rxbinding2.view.RxView;
import com.jakewharton.rxbinding2.widget.RxTextView;
import com.joyson.app.R;
import com.joyson.app.common.ui.SimpleActivity;
import com.joyson.app.module.home.HomeActivity;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;

/**
 * @author joyson
 * @create 2018-10-25
 */
public class LoginActiviy extends SimpleActivity {

    @Override
    protected void initEventAndData() {
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_login;
    }



    private void showLoginDialog() {
        View contentView = LayoutInflater.from(this).inflate(R.layout.dialog_login, null);
        EditText et_pls_input_mobile=contentView.findViewById(R.id.et_pls_input_mobile);
        EditText et_auth_code=contentView.findViewById(R.id.et_auth_code);
        ImageView iv_pwd_hint=contentView.findViewById(R.id.iv_pwd_hint);
        TextView tv_pwd_forget=contentView.findViewById(R.id.tv_pwd_forget);
        ImageView iv_login_cancel=contentView.findViewById(R.id.iv_login_cancel);
        ImageView iv_login_ok=contentView.findViewById(R.id.iv_login_ok);


        final CustomPopWindow customPopWindow = new CustomPopWindow.PopupWindowBuilder(this)
                .setView(contentView)
                .enableBackgroundDark(true)
//                .size(contentView.getMeasuredWidth(), ConvertUtils.dp2px(300))
                .size( ConvertUtils.dp2px(300), ConvertUtils.dp2px(260))
                .setBgDarkAlpha(0.5f)
                .enableOutsideTouchableDissmiss(true)
                .setAnimationStyle(R.style.BottomPopAnim)
                .create()
//        customPopWindow.showAsDropDown(tv_center,0,  - (tv_center.getHeight() + customPopWindow.getHeight()));
                //在屏幕最底部展示
                .showAtLocation(this.getWindow().getDecorView(), Gravity.CENTER, 0, 0);

        iv_login_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                customPopWindow.dissmiss();
            }
        });
        iv_login_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                customPopWindow.dissmiss();
                startActivity(new Intent(LoginActiviy.this,HomeActivity.class));
            }
        });
    }

    private void showRegisterDialog() {
        View contentView = LayoutInflater.from(this).inflate(R.layout.dialog_register_auth_code, null);
        EditText et_pls_input_mobile=contentView.findViewById(R.id.et_pls_input_mobile);
        EditText et_auth_code=contentView.findViewById(R.id.et_auth_code);
        LinearLayout ll_get_auth_code=contentView.findViewById(R.id.ll_get_auth_code);
        ImageView iv_register_cancel=contentView.findViewById(R.id.iv_register_cancel);
        ImageView iv_register_ok=contentView.findViewById(R.id.iv_register_ok);

        final CustomPopWindow customPopWindow = new CustomPopWindow.PopupWindowBuilder(this)
                .setView(contentView)
                .enableBackgroundDark(true)
//                .size(contentView.getMeasuredWidth(), ConvertUtils.dp2px(300))
                .size( ConvertUtils.dp2px(300), ConvertUtils.dp2px(300))
                .setBgDarkAlpha(0.5f)
                .enableOutsideTouchableDissmiss(true)
                .setAnimationStyle(R.style.BottomPopAnim)
                .create()
//        customPopWindow.showAsDropDown(tv_center,0,  - (tv_center.getHeight() + customPopWindow.getHeight()));
                //在屏幕最底部展示
                .showAtLocation(this.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
    }

    private void showLoginPicker() {
        View contentView = LayoutInflater.from(this).inflate(R.layout.dialog_login_picker, null);
        ImageView iv_login_mobile = contentView.findViewById(R.id.iv_login_mobile);
        ImageView iv_login_qq = contentView.findViewById(R.id.iv_login_qq);
        ImageView iv_login_wechat = contentView.findViewById(R.id.iv_login_wechat);

        iv_login_mobile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showLoginDialog();
            }
        });
        iv_login_qq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        iv_login_wechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        final CustomPopWindow customPopWindow = new CustomPopWindow.PopupWindowBuilder(this)
                .setView(contentView)
                .enableBackgroundDark(true)
//                .size(contentView.getMeasuredWidth(), ConvertUtils.dp2px(300))
                .size(ScreenUtils.getScreenWidth(), ConvertUtils.dp2px(120))
                .setBgDarkAlpha(0.5f)
                .enableOutsideTouchableDissmiss(true)
                .setAnimationStyle(R.style.BottomPopAnim)
                .create()
//        customPopWindow.showAsDropDown(tv_center,0,  - (tv_center.getHeight() + customPopWindow.getHeight()));
                //在屏幕最底部展示
                .showAtLocation(this.getWindow().getDecorView(), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }

    @OnClick({R.id.tv_login, R.id.tv_register})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_login:
                showLoginPicker();
                break;
            case R.id.tv_register:
                showRegisterDialog();
                break;
        }
    }
}
